package cn.kgc.ssm.controller;

import cn.kgc.ssm.dto.MemberPageDTO;
import cn.kgc.ssm.entity.Member;
import cn.kgc.ssm.response.ResponseResult;
import cn.kgc.ssm.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author 课工场
 * @date 2024/11/18
 * @description 会员操作控制层
 */
@RestController
@RequestMapping("member")
public class MemberController {


    @Autowired
    private MemberService memberService;

    @GetMapping("page")
    public ResponseResult memberPage(MemberPageDTO memberPageDTO) {

      return memberService.memberPage(memberPageDTO);
    }


    // 管理员添加会员
    @PostMapping("add")
    public ResponseResult addMember(Member member) {

        return memberService.addMember(member);
    }

    // 普通用户注册会员
    @PostMapping("front/register")
    public ResponseResult registerMember(Member member){

        return memberService.registerMember(member);
    }


    // 会员登录
    @PostMapping("front/login")
    public ResponseResult login(Member member, HttpSession session){

        return memberService.login(member,session);
    }


    // edit  编辑会员信息
    @PostMapping("edit")
    public ResponseResult editMember(Member member){

        return memberService.editMember(member);
    }

    // 删除  delete
    @PostMapping("delete")
    public ResponseResult deleteMember(@RequestBody List<Integer> ids){

        return memberService.deleteMember(ids);
    }


}
